﻿package pages {
	import flash.display.MovieClip;

	/**
	 * @author Hank
	 * 2009-9-29
	 */
	public class Model {
		static private var _instance : Model;
		private var _dir : String;
		private var _pid : uint;

		static private const _pages : Array = ["home", "retro", "legend", "collect", "register", "technology", "forge"];		
		static public const FORWARD : String = "forward";
		static public const BACKWARD : String = "backward";
		static public const JUMP : String = "jump";
		static public const JUMPFrame : uint = 20;

		public function Model() {
			instance = this;
			pid = 0;
		}

		static public function set instance(modelInstance : Model) : void {
			_instance = modelInstance;
		}

		static public function get instance() : Model {
			return _instance;
		}

		static public function getPagesWithId(id : uint) : String {
			return _pages[id];
		}

		public function set pid(id : uint) : void {
			_pid = id;
		}

		public function get pid() : uint {
			return _pid;
		}

		public function set dir(str : String) : void {
			_dir = str;			
			if(str == FORWARD) {
				pid = (pid - 1) < 0 ? _pages.length - 1 : (pid - 1);
			} else if(str == BACKWARD) {
				pid = (pid + 1) >= _pages.length ? 0 : (pid + 1);
			}
		}

		public function get dir() : String {
			return _dir;
		}

		public function getJumpFrame(target : MovieClip) : uint {
			var frame : uint = target.totalFrames > 20 ? target.totalFrames - JUMPFrame : 0;
			return frame;
		}
	}
}
